Lab 18

  1. Turn in a solution to Example 3 from the Lab 18 PowerPoint. Include a main function that calls your sumCubes function, testing it with two or three sensible inputs.
  2. Write a function called twoPart that returns the largest power of 2 that divides a positive integer parameter. For example, a program that uses the function twoPart follows. Submit a complete C++ program that contains your function and uses the main function below.
  3. int main() { cout << twoPart(16) << endl; // prints 16 cout << twoPart(666) << endl; // prints 2 cout << twoPart(777) << endl; // prints 1 return 0; }

  4. Write a function called biggestDigit that finds the biggest digit in an integer parameter. (Assume that the input parameter is not negative.) For example, a program that uses the function biggestDigit follows. Submit a complete C++ program that contains your function and uses the main function below.
  5. int main() { cout << biggestDigit(29) << endl; // prints 9 cout << biggestDigit(31415) << endl; // prints 5 cout << biggestDigit(7) << endl; // prints 7 return 0; }
  6. Write a function called sumDigits that recursively sums all digits of an integer. (Assume the input parameter is not negative.) For example, a program that uses the function biggestDigit follows. Submit a complete C++ program that contains your function and uses the main function below.
  7. int main() { cout << sumDigits(912) << endl; // prints 12 cout << sumDigits(3275) << endl; // prints 17 return 0; }
  8. Write a function called removeOddDigits that takes an integer parameter and returns a number with all odd digits removed. (Assume the input parameter is not negative.) For example, a program that uses the function removeOddDigits follows. Submit a complete C++ program that contains your function and uses the main function below.
  9. int main() { cout << removeOddDigits(792) << endl; // prints 2 cout << removeOddDigits(37) << endl; // prints 0 cout << removeOddDigits(222) << endl; // prints 222 return 0; }